package com.daqian.chance.example.admin.modules.system.controller;

import com.daqian.chance.common.base.BaseController;
import com.daqian.chance.core.rest.RestResult;
import com.daqian.chance.example.admin.modules.system.po.dto.SysMenuDTO;
import com.daqian.chance.example.admin.modules.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统-菜单表 前端控制器
 * </p>
 * @author daqian
 * @since 2019-08-08
 */
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController extends BaseController {

    @Autowired
    private ISysMenuService iSysMenuService;


    /**
     * 分页查询 系统-菜单表
     * @author daqian
     */
    @GetMapping("page")
    public RestResult page(SysMenuDTO sysMenuDTO) {
        return RestResult.ok(iSysMenuService.page(sysMenuDTO));
    }

    /**
     * 根据id查询 系统-菜单表
     * @author daqian
     */
    @GetMapping("info/{sysMenuId}")
    public RestResult info(@PathVariable("sysMenuId") Long sysMenuId) {
        return RestResult.ok(iSysMenuService.getById(sysMenuId));
    }

    /**
     * 保存 系统-菜单表
     * @author daqian
     */
    @PostMapping("save")
    public RestResult save(@RequestBody SysMenuDTO sysMenuDTO) {
        iSysMenuService.save(sysMenuDTO.convertToEntity());
        return RestResult.ok();
    }

    /**
     * 更新 系统-菜单表
     * @author daqian
     */
    @PostMapping("update/{sysMenuId}")
    public RestResult remove(@PathVariable("sysMenuId") Long sysMenuId, @RequestBody SysMenuDTO sysMenuDTO) {
        iSysMenuService.updateById(sysMenuDTO.convertToEntity().setId(sysMenuId));
        return RestResult.ok();
    }

    /**
     * 根据id删除 系统-菜单表
     * @author daqian
     */
    @DeleteMapping("{sysMenuId}")
    public RestResult delete(@PathVariable("sysMenuId") Long sysMenuId) {
        iSysMenuService.removeById(sysMenuId);
        return RestResult.ok();
    }

}
